<script>
  let arr = [1, 2, 3];
  let total = 0;
  $: total = arr.reduce((acc, cur) => acc + cur, 0);
  const arrPush = () => {
    arr.push(arr.length + 1);
    // 如果不加下面这句话，虽然arr中元素个数是增加了，但是不会被监听到
    // arr = [...arr];
    console.log(arr);
  };
</script>

<main>
  <p>{arr.join(" + ")} = {total}</p>
  <button on:click={arrPush}>arr增加元素</button>
</main>
